home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.03 Mar 95 / 11.03 Tips < prev    next >
Encoding:
Text File  |  1995-01-26  |  2.8 KB  |  96 lines  |  [TEXT/R*ch]

  1. Hey, Finder, Pay Attention!
  2. I have run into several things which  change a file’s creator but the
  3. Finder doesn’t update the file’s icon right away.  The user often has
  4. to close and reopen the Finder window to get the proper icons to
  5. appear. If your application needs to fiddle with a file’s creator type
  6. or other attributes, you can solve the above problem by changing the
  7. ioDrMdDat field of your file’s parent directory.  This “tricks” the
  8. Finder into updating the window.
  9.  
  10. void ForceFinderToUpdateFileIcon(
  11.                                     FSSpecPtr theFile) 
  12. {
  13. CInfoPBRec    tempPB;
  14.  
  15. if(theFile != 0L)
  16.  {
  17.     tempPB.dirInfo.ioNamePtr = 0L;
  18.     tempPB.dirInfo.ioVRefNum=theFile->vRefNum;
  19.     tempPB.dirInfo.ioFDirIndex = -1;
  20.     tempPB.dirInfo.ioDrDirID = theFile->parID;
  21.  
  22.     if(PBGetCatInfoSync(&tempPB) == noErr) 
  23.     {
  24.     tempPB.dirInfo.ioDrMdDat = LMGetTime();
  25.     tempPB.dirInfo.ioDrDirID = theFile->parID;
  26.     PBSetCatInfoSync(&tempPB);
  27.     }
  28.  } 
  29. }
  30. – Craig Marciniak
  31. TemplarDev@aol.com
  32.  
  33. Hot Tip for Hot Keys
  34. One of the things I appreciate in applications is the ability to select  
  35. buttons with keystrokes (the keyboard shortcut is know as a hotkey).  
  36. The following code example adds hotkey functionality to alert dialogs 
  37. and can be easily added to modal dialogs.  The next time you use an alert, 
  38. add AlertKeyProc to the function and you will have instant hotkey 
  39. functionality. Simply change 
  40.         CautionAlert(ALERT_ID, NIL) 
  41. to
  42.         CautionAlert(SAVE_ALERT_ID, AlertKeyProc)
  43.  
  44. #include <Dialogs.h>
  45. #define kEnterKey               3
  46. #define kReturnKey              13
  47. #define kEscapeKey              27
  48.  
  49. pascal Boolean AlertKeyProc(DialogPtr theDialog, EventRecord *e, short *itemHit)
  50. {
  51.    char         theChar;
  52.    short        num, i, iType;
  53.    Handle       iHandle;
  54.    Rect         iRect;
  55.    Str255       iText;
  56.    long         finalTicks;
  57.  
  58.    switch( e->what )
  59.    {
  60.       case keyDown:
  61.       case autoKey:
  62.          theChar = (e->message & charCodeMask);
  63.          if(theChar == kReturnKey || theChar == kEnterKey)
  64.          {
  65.             *itemHit = 1;
  66.             return( TRUE );
  67.          }
  68.          else if(theChar == kEscapeKey)
  69.          {
  70.             *itemHit = 2;
  71.             return( TRUE );
  72.          }
  73.          else
  74.          {
  75.             num = CountDITL( theDialog );
  76.             for(i=0; i<num; i++)
  77.             {
  78.                GetDItem(theDialog, i, &iType, &iHandle, &iRect);
  79.                if(iType == ctrlItem + btnCtrl)
  80.                {// If the button is a push button
  81.                   GetCTitle((ControlHandle )iHandle, iText);
  82.                   if(theChar == iText[1] || 
  83.                      theChar == tolower(iText[1]))
  84.                   {
  85.                      *itemHit = i;
  86.                      HiliteControl((ControlHandle )iHandle, 1);
  87.                      return( TRUE );
  88.                   }
  89.                }
  90.             }
  91.          }
  92.          break;
  93.    }
  94.    return( FALSE );
  95. }
  96.